package com.wans.ssq.config;

import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.time.format.DateTimeFormatter;

@Configuration
public class JacksonConfig {

    private static final DateTimeFormatter DATE_TIME_FORMATTER = 
        DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

    /**
     * 全局配置LocalDateTime的序列化与反序列化规则
     */
    @Bean
    public Jackson2ObjectMapperBuilderCustomizer jsonCustomizer() {
        return builder -> {
            // 序列化规则
            builder.serializers(new LocalDateTimeSerializer(DATE_TIME_FORMATTER));
            
            // 反序列化规则
            builder.deserializers(new LocalDateTimeDeserializer(DATE_TIME_FORMATTER));
            
            // 设置时区
            builder.timeZone("GMT+8");
        };
    }
}